package com.infodms.dms.actions.sales.storageManage;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.infodms.dms.bean.AclUserBean;
import com.infodms.dms.common.Constant;
import com.infodms.dms.common.ErrorCodeConstant;
import com.infodms.dms.common.materialManager.MaterialGroupManagerDao;
import com.infodms.dms.dao.sales.storageManage.AddressAddQueryDAO;
import com.infodms.dms.exception.BizException;
import com.infodms.dms.util.CommonUtils;
import com.infoservice.mvc.context.ActionContext;
import com.infoservice.mvc.context.RequestWrapper;
import com.infoservice.po3.bean.PageResult;

public class AddressAddQuery {
	public Logger logger = Logger.getLogger(AddressAddQuery.class);
	private ActionContext act = ActionContext.getContext();
	RequestWrapper request = act.getRequest();
	private static final AddressAddQueryDAO dao = new AddressAddQueryDAO ();
	public static final AddressAddQueryDAO getInstance() {
		return dao;
	}
	private final String  addressAddQueryInitUrl = "/jsp/sales/storageManage/addressAddQueryInit.jsp";
	
	
	public void addressAddQueryInit(){
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
			Long poseId = logonUser.getPoseId();
			List<Map<String, Object>> areaList = MaterialGroupManagerDao.getDealerBusiness(poseId.toString());
			act.setOutData("areaList", areaList);
			act.setForword(addressAddQueryInitUrl);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "经销商地址更改申请查询：页面初始化");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	} 
	/**
	 * 查询修改历史
	 * */
	public void changeList(){
		AclUserBean logonUser = null;
		try {
			logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
			String dealerId = "";
			String areaId = CommonUtils.checkNull(request.getParamValue("areaId"));
			String address = CommonUtils.checkNull(request.getParamValue("address"));
			String status = CommonUtils.checkNull(request.getParamValue("status"));
			String dealerIds = logonUser.getDealerId();
			if ("".equals(areaId)) {
				dealerId = dealerIds;
			}else{
				dealerId = dealerIds;
			}
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage"))
					: 1;
			PageResult<Map<String, Object>> ps = dao.getChangeList(areaId, status,dealerId, address, Constant.PAGE_SIZE, curPage);
			act.setOutData("ps", ps);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "查询修改历史");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
}
